﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebClient.ElectricCarService;

namespace WebClient
{
    public partial class RoutePlanner : System.Web.UI.Page
    {
        private IElectricCarService _serviceClient = new ElectricCarServiceClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected override void OnInit(EventArgs e)
        {
            LoadLocations();
            base.OnInit(e);
        }


        private void LoadLocations()
        {

            IList<Location> locations = _serviceClient.GetAllLocations();

            drpDownFrom.DataSource = locations;
            drpDownFrom.DataTextField = "Identifier";
            drpDownFrom.DataBind();

            drpDownTo.DataSource = locations;
            drpDownTo.DataTextField = "Identifier";
            drpDownTo.DataBind();

            Session["locations"] = locations;

        }

        protected void btnRoute_Click(object sender, EventArgs e)
        {

            IList<Location> locations = (IList<Location>)Session["locations"];

            Location to = locations[drpDownTo.SelectedIndex];
            Location from = locations[drpDownFrom.SelectedIndex];

            lstRoute.DataSource = _serviceClient.FindPath(from, to).Description;
            lstRoute.DataBind();

        }

    }
}